package com.mchsdk.paysdk.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.mchsdk.paysdk.bean.MCPayModel;
import com.mchsdk.paysdk.utils.MCHInflaterUtils;

public class PTBPayResultActivity extends Activity {

	TextView txtPrice;
	TextView txtPtbprice;
	TextView txtGoodsName;
	TextView txtTradeNo;
	TextView txtFinish;
	Button btnSubmit;
	/**
	 * 监听退出的事件
	 */
	private OnClickListener finishClick = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			MCPayModel.Instance().getPck().callback("0");
			finish();
		}
	};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(MCHInflaterUtils.getIdByName(getApplication(), "layout",
				"activity_mch_ptb_pay_info"));
		initView();
		initData();
	}

	/**
	 * 初始化控件
	 */
	private void initView() {
		txtPrice = (TextView) findViewById(MCHInflaterUtils
				.getIdByName(this, "id", "txt_price"));
		txtPtbprice = (TextView) findViewById(MCHInflaterUtils
				.getIdByName(this, "id", "txt_ptb_price"));
		txtGoodsName = (TextView) findViewById(MCHInflaterUtils
				.getIdByName(this, "id", "txt_goods_name"));
		txtTradeNo = (TextView) findViewById(MCHInflaterUtils
				.getIdByName(this, "id", "txt_tradeno"));
		txtFinish = (TextView) findViewById(MCHInflaterUtils
				.getIdByName(this, "id", "txt_finish"));
		txtFinish.setOnClickListener(finishClick);
		btnSubmit = (Button) findViewById(MCHInflaterUtils
				.getIdByName(this, "id", "btn_submit"));
		btnSubmit.setOnClickListener(finishClick);
		
	}

	/**
	 * 给控件赋值
	 */
	private void initData() {
		Bundle bundle = getIntent().getExtras();
		txtPrice.setText(bundle.getCharSequence("price"));
		txtPtbprice.setText(bundle.getCharSequence("price"));
		txtGoodsName.setText(bundle.getCharSequence("productname"));
		txtTradeNo.setText(bundle.getCharSequence("tradeno"));
		
	}

	/**
	 * 监听 返回键
	 */
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(event.getKeyCode() == KeyEvent.KEYCODE_BACK){
			MCPayModel.Instance().getPck().callback("0");
			finish();
		}
		return super.onKeyDown(keyCode, event);
	}
}
